<template>
  <div id="assessdetail">
    <el-form :model="editForm" label-width="300px" ref="editForm" :inline="true" style="padding:10px 0 0;clear:both" :rules="editFormRules" v-show="!pageLoading">
      <table cellspacing="0" cellpadding="0" class="mytable">
        <tr>
          <th style="min-width:100px;" >承担纪检工作机构名称</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.deptName}}</template>
            </template>
            <template v-else>
              <el-form-item prop="deptName">
                <el-input v-model="editForm.deptName" style="width: 300px;" />
              </el-form-item>
            </template>
          </td>
          <th style="min-width:100px;" >机构类型</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.deptType}}</template>
            </template>
            <template v-else>
              <el-form-item prop="deptType">
                <el-select v-model="editForm.deptType" placeholder="请选择" style="width: 300px;">
                  <el-option v-for="item in deptTypeOptions" :key="'deptType_' + item" :label="item" :value="item" />
                </el-select>
                <div style="font-size: 14px; font-weight: bold; color: red; line-height: 20px; margin-top: 6px;">
                  其他纪检机构范围：直属企事业单位、海区局所属事业单位、测绘局所属事业单位等
                  <br />
                  垂管单位省级纪检机构范围：九个督察局、三个海区局机关、四个测绘局机关等
                </div>
              </el-form-item>
            </template>
          </td>
        </tr>
      </table>
      <h3>编制</h3>
      <table cellspacing="0" cellpadding="0" class="mytable">
        <tr>
          <th style="min-width:100px;" >行政编制</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.unitOrg1}}</template>
            </template>
            <template v-else>
              <el-form-item prop="unitOrg1">
                <el-input-number v-model="editForm.unitOrg1" :step="1" :min="0" @change="sumOrgNum" step-strictly />
              </el-form-item>
            </template>
          </td>
          <th style="min-width:100px;" >事业编制</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.unitOrg2}}</template>
            </template>
            <template v-else>
              <el-form-item prop="unitOrg2">
                <el-input-number v-model="editForm.unitOrg2" :step="1" :min="0" @change="sumOrgNum" step-strictly />
              </el-form-item>
            </template>
          </td>
        </tr>
        <tr>
          <th style="min-width:100px;" >企业编制</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.unitOrg3}}</template>
            </template>
            <template v-else>
              <el-form-item prop="unitOrg3">
                <el-input-number v-model="editForm.unitOrg3" :step="1" :min="0" @change="sumOrgNum" step-strictly />
              </el-form-item>
            </template>
          </td>
          <th style="min-width:100px;" >编制总数</th>
          <td style="min-width:200px;">
            <template >
              <template><div :style="readOnly?'':'margin-top:20px'">{{unitOrgSum}}</div></template>
            </template>
          </td>
        </tr>
      </table>
      <h3>领导职数</h3>
      <table cellspacing="0" cellpadding="0" class="mytable">
        <tr>
          <th style="min-width:100px; text-align: left;" colspan="4">按职务层次分（或相当职务层次）</th>
        </tr>
        <tr>
          <th style="min-width:100px;" >省部级副职</th>
          <td style="min-width:200px;" colspan="3">
            <template v-if="readOnly" >
              <template>{{editForm.l1}}</template>
            </template>
            <template v-else>
              <el-form-item prop="l1">
                <el-input-number v-model="editForm.l1" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
        </tr>
        <tr>
          <th style="min-width:100px;" >厅局级正职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.l2}}</template>
            </template>
            <template v-else>
              <el-form-item prop="l2">
                <el-input-number v-model="editForm.l2" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
          <th style="min-width:100px;" >厅局级副职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.l3}}</template>
            </template>
            <template v-else>
              <el-form-item prop="l3">
                <el-input-number v-model="editForm.l3" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
        </tr>
        <tr>
          <th style="min-width:100px;" >县处级正职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.l4}}</template>
            </template>
            <template v-else>
              <el-form-item prop="l4">
                <el-input-number v-model="editForm.l4" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
          <th style="min-width:100px;" >县处级副职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.l5}}</template>
            </template>
            <template v-else>
              <el-form-item prop="l5">
                <el-input-number v-model="editForm.l5" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
        </tr>
        <tr>
          <th style="min-width:100px;" >乡科级正职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.l6}}</template>
            </template>
            <template v-else>
              <el-form-item prop="l6">
                <el-input-number v-model="editForm.l6" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
          <th style="min-width:100px;" >乡科级副职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.l7}}</template>
            </template>
            <template v-else>
              <el-form-item prop="l7">
                <el-input-number v-model="editForm.l7" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
        </tr>
        <tr>
          <th style="min-width:100px; text-align: left;" colspan="4">领导班子职数</th>
        </tr>
        <tr>
          <th style="min-width:100px;" >正职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.lz}}</template>
            </template>
            <template v-else>
              <el-form-item prop="lz">
                <el-input-number v-model="editForm.lz" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
          <th style="min-width:100px;" >副职</th>
          <td style="min-width:200px;">
            <template v-if="readOnly" >
              <template>{{editForm.lf}}</template>
            </template>
            <template v-else>
              <el-form-item prop="lf">
                <el-input-number v-model="editForm.lf" :step="1" :min="0" step-strictly />
              </el-form-item>
            </template>
          </td>
        </tr>
      </table>
      <!-- <template v-if="project.projectVersion&&project.projectVersion==='v2'">
        <h3>人员交流情况（2017年11月以来）</h3>
        <table cellspacing="0" cellpadding="0" class="mytable">
          <tr>
            <th style="min-width:100px;" >纪检监察系统内部交流人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num1_1}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num1_1">
                  <el-input-number v-model="editForm.num1_1" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
            <th style="min-width:100px;" >交流到纪检监察系统外人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num1_2}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num1_2">
                  <el-input-number v-model="editForm.num1_2" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
          </tr>
          <tr>
            <th style="min-width:100px;" >人员交流情况描述</th>
            <td style="min-width:200px;" colspan="3">
              <template v-if="readOnly" >
                <template>{{editForm.content1}}</template>
              </template>
              <template v-else>
                <el-form-item prop="content1">
                  <el-input type="textarea" v-model="editForm.content1" :rows="5" :maxlength="1000" style="width:800px" />
                </el-form-item>
              </template>
            </td>
          </tr>
        </table>
        <h3>在岗人员严重疾病情况</h3>
        <table cellspacing="0" cellpadding="0" class="mytable">
          <tr>
            <th v-if="readOnly" style="min-width:100px;vertical-align: top;" >实有人数</th>
            <th v-else style="min-width:100px;" >实有人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num2_1}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num2_1">
                  <el-input-number v-model="editForm.num2_1" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
            <th style="min-width:100px;" >其中患有抑郁症精神分裂等精神疾病人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num2_2}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num2_2">
                  <el-input-number v-model="editForm.num2_2" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
          </tr>
          <tr>
            <th style="min-width:100px;" >在岗人员严重疾病情况描述</th>
            <td style="min-width:200px;" colspan="3">
              <template v-if="readOnly" >
                <template>{{editForm.content2}}</template>
              </template>
              <template v-else>
                <el-form-item prop="content2">
                  <el-input type="textarea" v-model="editForm.content2" :rows="5" :maxlength="1000" style="width:800px" />
                  <div style="font-weight:bolder;color:red">注：填写本栏需细化说明人员姓名、性别、年龄、职务职级、所患疾病及后续保障等情况。</div>
                </el-form-item>
              </template>
            </td>
          </tr>
        </table>
        <h3>在岗人员伤残情况</h3>
        <table cellspacing="0" cellpadding="0" class="mytable">
          <tr>
            <th style="min-width:100px;" >持有残疾人证人数</th>
            <td style="min-width:200px;" colspan="3">
              <template v-if="readOnly" >
                <template>{{editForm.num3}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num3">
                  <el-input-number v-model="editForm.num3" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
          </tr>
          <tr>
            <th style="min-width:100px;" >在岗人员伤残情况描述</th>
            <td style="min-width:200px;" colspan="3">
              <template v-if="readOnly" >
                <template>{{editForm.content3}}</template>
              </template>
              <template v-else>
                <el-form-item prop="content3">
                  <el-input type="textarea" v-model="editForm.content3" :rows="5" :maxlength="1000" style="width:800px" />
                  <div style="font-weight:bolder;color:red">注：填写本栏需细化说明人员姓名、性别、年龄、职务职级、伤残缘由、程度及后续保障等情况。</div>
                </el-form-item>
              </template>
            </td>
          </tr>
        </table>
        <h3>在岗人员死亡情况（2017年11月以来）</h3>
        <table cellspacing="0" cellpadding="0" class="mytable">
          <tr>
            <th style="min-width:100px;" >烈士人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num4_1}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num4_1">
                  <el-input-number v-model="editForm.num4_1" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
            <th style="min-width:100px;" >因公牺牲人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num4_2}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num4_2">
                  <el-input-number v-model="editForm.num4_2" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
          </tr>
          <tr>
            <th style="min-width:100px;" >自杀身亡人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num4_3}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num4_3">
                  <el-input-number v-model="editForm.num4_3" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
            <th style="min-width:100px;" >其他人数</th>
            <td style="min-width:200px;">
              <template v-if="readOnly" >
                <template>{{editForm.num4_4}}</template>
              </template>
              <template v-else>
                <el-form-item prop="num4_4">
                  <el-input-number v-model="editForm.num4_4" :step="1" :min="0" step-strictly />
                </el-form-item>
              </template>
            </td>
          </tr>
          <tr>
            <th style="min-width:100px;" >在岗人员死亡情况描述</th>
            <td style="min-width:200px;" colspan="3">
              <template v-if="readOnly" >
                <template>{{editForm.content4}}</template>
              </template>
              <template v-else>
                <el-form-item prop="content4">
                  <el-input type="textarea" v-model="editForm.content4" :rows="5" :maxlength="1000" style="width:800px" />
                  <div style="font-weight:bolder;color:red">注：填写本栏需细化说明人员姓名、性别、年龄、职务职级、死亡时间、死亡原因及后续抚恤保障等情况；烈士、因公牺牲、因工死亡人员遗属现状。</div>
                </el-form-item>
              </template>
            </td>
          </tr>
        </table>
      </template> -->
      <h3 v-if="(fileList1 && fileList1.length > 0)||!readOnly">存在列编在纪检机构内或由纪检机构统一管理的情形，需附件细化说明</h3>
      <el-upload
        v-if="!readOnly"
        v-model="fileList1"
        :action="$http.defaults.baseURL+$http.defaults.unitReportAPI +'api/file/upload/'"
        :on-preview="handlePreview"
        :on-success="(response, file, fileList)=>{return handleUploadSucc1(response, file, fileList)}"
        :on-error="uploadError"
        :before-remove="beforeRemove"
        :before-upload="beforeUpload"
        :show-file-list="false"
        style="margin-left:10px;"
      >
        <el-button size="small" type="primary">上传附件</el-button>
      </el-upload>
      <el-table v-if="fileList1 && fileList1.length > 0" :data="fileList1" highlight-current-row style="width: 100%;border:1px solid #95B8E7;margin: 10px;" border>
        <el-table-column prop="file" label="附件">
          <template slot-scope="scope">
            <a v-if="scope.row.fileId" :href="$http.defaults.baseURL + $http.defaults.unitReportAPI + 'api/file/download?id='+scope.row.fileId">{{scope.row.fileName}}</a>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" v-if="!readOnly">
          <template slot-scope="scope">
            <el-popconfirm
              title="这是一段内容确定删除吗？"
              @confirm="delFile1(scope.row.fileId)"
              @onConfirm="delFile1(scope.row.fileId)"
            >
              <el-button slot="reference" size="mini" type="danger">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <h3 v-if="(fileList2 && fileList2.length > 0)||!readOnly">存在其他编制或暂未核定编制的，需附件细化说明</h3>
      <el-upload
        v-if="!readOnly"
        v-model="fileList2"
        :action="$http.defaults.baseURL+$http.defaults.unitReportAPI +'api/file/upload/'"
        :on-preview="handlePreview"
        :on-success="(response, file, fileList)=>{return handleUploadSucc2(response, file, fileList)}"
        :on-error="uploadError"
        :before-remove="beforeRemove"
        :before-upload="beforeUpload"
        :show-file-list="false"
        style="margin-left:10px;"
      >
        <el-button size="small" type="primary">上传附件</el-button>
      </el-upload>
      <el-table v-if="fileList2 && fileList2.length > 0" :data="fileList2" highlight-current-row style="width: 100%;border:1px solid #95B8E7;margin:10px;" border>
        <el-table-column prop="file" label="附件">
          <template slot-scope="scope">
            <a v-if="scope.row.fileId" :href="$http.defaults.baseURL + $http.defaults.unitReportAPI + 'api/file/download?id='+scope.row.fileId">{{scope.row.fileName}}</a>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" v-if="!readOnly">
          <template slot-scope="scope">
            <el-popconfirm
              title="这是一段内容确定删除吗？"
              @confirm="delFile2(scope.row.fileId)"
              @onConfirm="delFile2(scope.row.fileId)"
            >
              <el-button slot="reference" size="mini" type="danger">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <!-- <h3>纪检监察机构所获表彰奖励情况（2017年11月以来）</h3>
      <div>
        <el-dialog
          title="新增"
          :visible.sync="awardFormVisible"
          append-to-body
          width="700px" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
          <el-form :model="awardForm" ref="awardForm" style="margin:10px 10px 0;clear:both" :rules="awardFormRules" label-width="100px">
            <el-form-item label="类型" prop="awardType">
              <el-select v-model="awardForm.awardType" placeholder="请选择" style="width:150px">
                <el-option label="国家级" value="国家级" />
                <el-option label="省部级" value="省部级" />
              </el-select>
            </el-form-item>
            <el-form-item label="奖励名称" prop="awardName">
              <el-input v-model="awardForm.awardName"  style="width:330px"></el-input>
            </el-form-item>
            <el-form-item label="附件" prop="job" v-if="awardForm.awardType==='国家级'">
              <el-upload
                v-model="fileList"
                :action="$http.defaults.baseURL+$http.defaults.unitReportAPI +'api/file/upload/'"
                :on-preview="handlePreview"
                :on-remove="(file, fileList)=>{return handleRemove(file, fileList)}"
                :on-success="(response, file, fileList)=>{return handleUploadSucc(response, file, fileList)}"
                :on-error="uploadError"
                :before-remove="beforeRemove"
                :before-upload="beforeUpload"
                :on-exceed="handleExceed"
                :limit="1"
                :file-list="fileList">
                <el-button size="small" type="primary">点击上传</el-button>
              </el-upload>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click.native="addAward">保存</el-button>
              注：国家级表彰奖励应上传附件予以细化说明。
            </el-form-item>
          </el-form>
        </el-dialog>
        <el-button v-if="!readOnly" type="success" style="margin:10px;" @click.native="showAwardForm">新增</el-button>
      </div>
      <el-table :data="awards" highlight-current-row style="width: 100%;border:1px solid #95B8E7;margin:0 10px 10px" border>
        <el-table-column type="index" label="序号" width="50" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column prop="awardType" label="类型" width="100">
        </el-table-column>
        <el-table-column prop="awardName" label="奖励名称">
        </el-table-column>
        <el-table-column prop="file" label="附件" width="300">
          <template slot-scope="scope">
            <a v-if="scope.row.fileId" :href="$http.defaults.baseURL + $http.defaults.unitReportAPI + 'api/file/download?id='+scope.row.fileId">{{scope.row.fileName}}</a>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" v-if="!readOnly">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="delAward(scope.$index)" v-if="!readOnly">删除</el-button>
          </template>
        </el-table-column>
      </el-table> -->
      <template v-if="!readOnly">
        <el-button type="primary" @click.native="editFormSubmit()" :loading="saveloading" style="margin-left:10px; margin-top: 10px;">保存</el-button>
      </template>
    </el-form>
  </div>
</template>

<script>
export default {
  watch: {
    timestamp: {
      handler (val) {
        this.awards = []
        this.editForm = {}
        this.editForm = {...this.unitData}
        this.fileList1 = this.unitData.fileList1
        this.fileList2 = this.unitData.fileList2
        if (this.editForm.awards) {
          this.awards = this.editForm.awards
        }
        this.sumOrgNum()
        this.saveloading = false
      },
      immediate: true
    },
    filterText (val) {
      this.$refs.tree.filter(val)
    }
  },
  props: {
    timestamp: '',
    projectId: null,
    readOnly: false,
    unitData: {},
    project: {}
  },
  data () {
    return {
      awardFormVisible: false,
      fileList: [],
      unitOrgSum: 0,
      editFormRules: {
        deptName: [{ required: true, message: '必填项', trigger: 'blur' }],
        deptType: [{ required: true, message: '必填项', trigger: 'blur' }],
        unitOrg1: [{ required: true, message: '必填项', trigger: 'blur' }],
        unitOrg2: [{ required: true, message: '必填项', trigger: 'blur' }],
        unitOrg3: [{ required: true, message: '必填项', trigger: 'blur' }],
        num1_1: [{ required: true, message: '必填项', trigger: 'blur' }],
        num1_2: [{ required: true, message: '必填项', trigger: 'blur' }],
        num2_1: [{ required: true, message: '必填项', trigger: 'blur' }],
        num2_2: [{ required: true, message: '必填项', trigger: 'blur' }],
        num3: [{ required: true, message: '必填项', trigger: 'blur' }],
        num4_1: [{ required: true, message: '必填项', trigger: 'blur' }],
        num4_2: [{ required: true, message: '必填项', trigger: 'blur' }],
        num4_3: [{ required: true, message: '必填项', trigger: 'blur' }],
        num4_4: [{ required: true, message: '必填项', trigger: 'blur' }],
        l1: [{ required: true, message: '必填项', trigger: 'blur' }],
        l2: [{ required: true, message: '必填项', trigger: 'blur' }],
        l3: [{ required: true, message: '必填项', trigger: 'blur' }],
        l4: [{ required: true, message: '必填项', trigger: 'blur' }],
        l5: [{ required: true, message: '必填项', trigger: 'blur' }],
        l6: [{ required: true, message: '必填项', trigger: 'blur' }],
        l7: [{ required: true, message: '必填项', trigger: 'blur' }],
        lz: [{ required: true, message: '必填项', trigger: 'blur' }],
        lf: [{ required: true, message: '必填项', trigger: 'blur' }]
      },
      limitNum: '',
      formData: [],
      pageLoading: false,
      saveloading: false,
      editForm: {
        deptName: '',
        deptType: '',
        unitOrg1: 0,
        unitOrg2: 0,
        unitOrg3: 0,
        num1_1: 0,
        num1_2: 0,
        num2_1: 0,
        num2_2: 0,
        num3: 0,
        num4_1: 0,
        num4_2: 0,
        num4_3: 0,
        num4_4: 0,
        content1: '',
        content2: '',
        content3: '',
        content4: '',
        l1: 0,
        l2: 0,
        l3: 0,
        l4: 0,
        l5: 0,
        l6: 0,
        l7: 0,
        lz: 0,
        lf: 0
      },
      awardForm: {
        type: null,
        name: '',
        filename: ''
      },
      formFiles: {},
      awards: [
      ],
      awardFormRules: {
        awardType: [{ required: true, message: '必填项', trigger: 'blur' }],
        awardName: [{ required: true, message: '必填项', trigger: 'blur' }]
      },
      deptTypeOptions: ['巡视机构', '机关纪委', '其他纪检机构', '垂管单位省级纪检机构', '垂管单位市级纪检机构', '垂管单位县级及以下纪检机构'],
      fileList1: [],
      fileList2: []
    }
  },
  methods: {
    handleUploadSucc1 (response, file, fileList) {
      this.saveloading = false
      if (response.success) {
        const fileObj = response.result[0]
        this.fileList1.push({
          fileName: fileObj.fileName + '.' + fileObj.fileType,
          fileId: fileObj.id
        })
        this.$message({
          message: '上传成功！',
          type: 'success'
        })
      } else {
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    delFile1 (fid) {
      this.fileList1 = this.fileList1.filter(item => item.fileId !== fid)
      this.$message({
        message: '删除成功！',
        type: 'success'
      })
    },
    handleUploadSucc2 (response, file, fileList) {
      this.saveloading = false
      if (response.success) {
        const fileObj = response.result[0]
        this.fileList2.push({
          fileName: fileObj.fileName + '.' + fileObj.fileType,
          fileId: fileObj.id
        })
        this.$message({
          message: '上传成功！',
          type: 'success'
        })
      } else {
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    delFile2 (fid) {
      this.fileList2 = this.fileList2.filter(item => item.fileId !== fid)
      this.$message({
        message: '删除成功！',
        type: 'success'
      })
    },
    showAwardForm () {
      this.awardForm = {
        type: null,
        name: '',
        filename: '',
        fileId: null,
        fileName: null
      }
      this.fileList = []
      this.awardFormVisible = true
    },
    delAward (index) {
      this.awards.splice(index, 1)
    },
    addAward () {
      this.$refs.awardForm.validate((valid) => {
        if (valid) {
          if (this.awardForm.awardType === '国家级' && !this.awardForm.fileId) {
            this.$message({
              message: '国家级表彰奖励应上传附件予以细化说明',
              type: 'error'
            })
            return false
          }
          if (this.awardForm.fileId) {
            this.awards.push({awardType: this.awardForm.awardType, awardName: this.awardForm.awardName, fileId: this.awardForm.fileId, fileName: this.awardForm.fileName})
          } else {
            this.awards.push({awardType: this.awardForm.awardType, awardName: this.awardForm.awardName})
          }
          this.awardForm = {
            type: null,
            name: '',
            filename: '',
            fileId: null,
            fileName: null
          }
          this.fileList = []
          this.awardFormVisible = false
        }
      })
    },
    sumOrgNum () {
      this.unitOrgSum = Math.round(this.editForm.unitOrg1 ? this.editForm.unitOrg1 : 0) + Math.round(this.editForm.unitOrg2 ? this.editForm.unitOrg2 : 0) + Math.round(this.editForm.unitOrg3 ? this.editForm.unitOrg3 : 0)
    },
    uploadError (err) {
      this.saveloading = false
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    beforeRemove (file, fileList) {
      if (file && file.status === 'success') {
        return this.$confirm(`确定删除 ${file.name}？`)
      }
    },
    handleUploadSucc (response, file, fileList) {
      console.log(fileList)
      this.saveloading = false
      if (response.success) {
        let fileObj = fileList[0].response.result[0]
        this.awardForm.fileName = fileObj.fileName + '.' + fileObj.fileType
        this.awardForm.fileId = fileObj.id
        this.$message({
          message: '上传成功！' + response.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    handlePreview (file) {
      if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(this.$http.defaults.baseURL + this.$http.defaults.unitReportAPI + 'api/file/download?id=' + file.id, file.name)
      } else {
        var link = document.createElement('a')
        link.download = file.name
        link.href = this.$http.defaults.baseURL + this.$http.defaults.unitReportAPI + 'api/file/download?id=' + file.id
        link.click()
        console.log(this.$http.defaults.unitReportAPI + 'api/file/download?id=' + file.id)
        window.URL.revokeObjectURL(link.href)
      }
    },
    handleRemove (file, fileList) {
      if (file && file.status === 'success') {
        console.log(file, fileList)
        const fid = file.id
        const url = 'api/file/remove'
        let para = {
          params: {
            id: fid
          }
        }
        this.$http.get(this.$http.defaults.unitReportAPI + url, para).then(res => {
          console.log('删除成功:', res)
          this.awardForm.fileName = null
          this.awardForm.fileId = null
          this.$message({
            message: '删除成功！',
            type: 'success'
          })
        })
      }
    },
    beforeUpload (file) {
      // const isFormat = file.name.indexOf('.zip') > 0
      const isLt50M = file.size / 1024 / 1024 < 5000
      if (!isLt50M) {
        this.$message.error('单个附件不能超过50M!')
      } else {
        this.saveloading = true
      }
      return isLt50M
    },
    handleExceed (files, fileList) {
      this.$message.warning(`上传文件个数超限`)
    },
    editFormSubmit () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          if (this.readOnly) {
            this.$message({
              message: '测试提交成功！',
              type: 'success'
            })
          } else {
            if ((this.editForm.num1_1 + this.editForm.num1_2 > 0) && (!this.editForm.content1 || this.editForm.content1 === '')) {
              this.$message({
                message: '人员交流人数大于0，请填写人员交流情况描述',
                type: 'error'
              })
              return false
            }
            if ((this.editForm.num2_1 + this.editForm.num2_2 > 0) && (!this.editForm.content2 || this.editForm.content2 === '')) {
              this.$message({
                message: '在岗人员严重疾病人数大于0，请填写在岗人员严重疾病情况描述',
                type: 'error'
              })
              return false
            }
            if ((this.editForm.num3 > 0) && (!this.editForm.content3 || this.editForm.content3 === '')) {
              this.$message({
                message: '在岗人员伤残人数大于0，请填写在岗人员伤残情况描述',
                type: 'error'
              })
              return false
            }
            if ((this.editForm.num4_1 + this.editForm.num4_2 + this.editForm.num4_3 + this.editForm.num4_4 > 0) && (!this.editForm.content4 || this.editForm.content4 === '')) {
              this.$message({
                message: '在岗人员死亡人数大于0，请填写在岗人员死亡情况描述',
                type: 'error'
              })
              return false
            }
            // 返回父页面数据
            this.editForm.fileList1 = this.fileList1
            this.editForm.fileList2 = this.fileList2
            this.saveloading = true
            this.$emit('saveUnitData', JSON.parse(JSON.stringify(this.editForm)))
            // this.editForm = {}
          }
        }
      })
    }
  },
  mounted () {
  }
}
</script>
<style>
#assessdetail .el-upload-list__item{
  width: 250px;
}
#assessdetail a{
  width: 200px;
}
.assessdetail .el-tabs__header{
  height: 29px;
  background: #FAFAFA;
  line-height: 30px;
  font-family: '宋体';
  padding:0 20px;
  border-bottom: 2px solid #E4E7ED;
  margin:0;
}
.assessdetail .el-tabs__item{
  line-height: 30px;
  height: 30px;
  font-weight:bolder;
}
  .cardtab .el-tabs__header{
    padding:0 !important;
    border-bottom:1px solid #E4E7ED;
  }
  #assessdetail .wboxs{
    height:45px;
    padding-top:0;
    margin-bottom: 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>

<style scoped>
  .tickettable th{
    font-weight:lighter;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    text-align: center;
  }
  .tickettable{
    width: 100%;
    border-left: 1px solid #95B8E7;
    border-top: 1px solid #95B8E7;
  }
  .tickettable td, .tickettable th{
    padding:5px 10px;
    margin:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体';
    border-bottom: 1px solid #95B8E7;
    border-right: 1px solid #95B8E7;
  }
  .tickettable td{
    vertical-align: middle;
    text-align: center;
    font-weight: bolder;
  }
  .mytable{
    border-top: 1px solid #74a6cc;
    border-left: 1px solid #74a6cc;
    margin:0 10px 10px;
    width: calc(100% - 20px);
  }
  .mytable th{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    line-height: 150%;
    background: #FAFAFA;
    width:200px;
    text-align:right;
  }
  .mytable td{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    vertical-align: top;
    line-height: 150%;
  }
</style>
